#include "../include/cc_dqueue.h"

static cc_bool_t cc_dequeue_push_back(cc_dqueue_t dqueue, void* data) {
	dqueue->size++;
	return dqueue->parent->insert_end(dqueue->parent, data);
}
static cc_bool_t  cc_dequeue_push_front(cc_dqueue_t dqueue, void* data) {
	dqueue->size++;
	return dqueue->parent->insert_head(dqueue->parent, data);
}

static void* cc_dequeue_pop_back(cc_dqueue_t dqueue) {
	dqueue->size--;
	return dqueue->parent->delete_end(dqueue->parent);
}
static void* cc_dequeue_pop_front(cc_dqueue_t dqueue) {
	dqueue->size--;
	return dqueue->parent->delete_head(dqueue->parent);
}

static void cc_dequeue_toString(cc_dqueue_t dqueue, void (*callback)(void* data)) {
	dqueue->parent->toString(dqueue->parent, callback);
}
static cc_bool_t cc_dequeue_isEmpty(cc_dqueue_t dqueue) {
	return dqueue->size == 0 ? 1 : 0;
}

static cc_bool_t cc_dequeue_length(cc_dqueue_t dqueue) {
	return dqueue->parent->size;
}

static void cc_dequeue_clear(cc_dqueue_t dqueue) {
	dqueue->parent->clear(dqueue->parent);
	dqueue->size = dqueue->parent->size;
}

static void cc_dqueue_free(cc_dqueue_t dqueue) {
	dqueue->parent->free(dqueue->parent);
	free(dqueue);
	dqueue = NULL;
}


cc_dqueue_t CC_New_DQueue(cc_uint8_t* name) {
	cc_dqueue_t dqueue = new(cc_dqueue);
	assert(dqueue != NULL);
	dqueue->parent = CC_New_List(name);
	dqueue->parent->parent->type = CC_Class_DQueue;  
	dqueue->size = 0;
	dqueue->pop_back = cc_dequeue_pop_back;
	dqueue->pop_front = cc_dequeue_pop_front;
	dqueue->push_back = cc_dequeue_push_back;
	dqueue->push_front = cc_dequeue_push_front;
	dqueue->toString = cc_dequeue_toString;
	dqueue->isEmpty = cc_dequeue_isEmpty;
	dqueue->length = cc_dequeue_length;
	dqueue->clear = cc_dequeue_clear;
	dqueue->free = cc_dqueue_free;
	return dqueue;
}